/*
 * @Author: tcosfish
 * @Date: 2022-08-19 09:39:45
 * @LastEditors: tcosfish
 * @LastEditTime: 2022-08-19 10:06:42
 * @FilePath: \loadFile\src\database\feat\saveDataByRecord.ts
 */

import { EntityTarget } from "typeorm"
import { AppDataSource } from "../index"

// data[0] { code: '6603.001', name: '财务费用 - 手续费', debit: 20, credit: 0 }

// TODO 新增数据, 与 subOperation 中的新增重复了
async function insertData<T>(data: any[][], entity: EntityTarget<T>) {
  data[0].shift() // 删除首行
  const connection = await AppDataSource.initialize()
  connection
    .createQueryBuilder()
    .insert()
    .into(entity)
    .values(data[0])
    .execute()
  console.log("分录数据已插入")
}

export { insertData }
